<template>
<view class="">
	<u-popup :show="show" mode="bottom" bgColor='#fff' :round="20" @close="close" @open="open" v-if="show">
		<view class="create-order br-20">
			<view class="title font-size-16 font-color-textPrimary font-w-bold flex flex-js-center flex-ai-center ptb-12">
				确认订单
			</view>
			<view class="row flex flex-ai-center flex-js-sb plr-16 ptb-12">
				<view class="label font-color-white_light_1">
					购买数量
				</view>
				<z-number-box v-model="form.num" :max="maxBuyCount" ></z-number-box>
			</view>
			<view class="row flex flex-ai-center flex-js-sb plr-16 ptb-12">
				<view class="label font-color-white_light_1">
					合计金额
				</view>
				<view class="value  font-color-theme font-size-22">
					<text class="font-size-12">
						￥
					</text>
					{{totalPrice}}
				</view>
			</view>
			<!-- <view class="btn-container flex flex-js-center pt-20 pb-8">
				<view class="btn bg-color-blue font-color-white font-size-16" @click="showBuyNeedFn">
					提交订单
				</view>
			</view> -->
			<w-button style='width: 686rpx;' class='ml-16 mtb-12' @click="submit">提交订单</w-button>
		</view>
	</u-popup>
</view>
</template>

<script>
	import productMixin from '@/mixins/product.js'
	import {createOrder} from '@/api/order/order.js'
	export default {
		name: "z-create-order",
		mixins:[productMixin],
		props:{
			show:{
				type:Boolean,
				default:false
			},
			product:{
				type:Object,
				default(){
					return {
						
					}
				}
			}
		},
		watch:{
			showBuyNeed(v){
				uni.$emit('postShowChange',v)
			},
			['product.id']: {
				deep: true,
				immediate: true,
				handler(v) {
					if (v) {
						if (this.product.id) {
							let key=this.product.id
							if(this.product.batch_id){
								key+='-'+this.product.batch_id
							}
							uni.$on('advanceChange-'+key,this.advanceChange)
						}
					}
				}
			}
		},
		model:{
			prop:'show',
			event:'change'
		},
		computed:{
			totalPrice(){
				return Number(this.form.num*this.product.price).toFixed(2)
			}
		},
		data() {
			return {
				showBuyNeed:false,
				check:false,
				isLoadAdvance:false,
				form:{
					num:1
				}
			};
		},
		mounted() {
			
		},
		methods:{
			advanceChange({isCoupon,isWhite}){
				this.isCoupon=isCoupon;
				this.isWhite=isWhite;
			},
			close(){
				this.$emit('change',false)
			},
			open(){
				this.$emit('change',true)
			},
			showBuyNeedFn(){
				this.showBuyNeed=true;
				this.$emit('change',false)
			},
			//创建订单
			submit(){
				// if(!this.check){
				// 	return uni.showToast({
				// 		icon:'none',
				// 		title:"请阅读并同意购买须知"
				// 	})
				// }
				this.close()
				// this.showBuyNeed=false;
				uni.setStorage({
					key: 'confirmOrder',
					data: {
						product: this.product,
						count: this.form.num,
						order_type: 1,
						maxCount:this.maxBuyCount
					},
					success() {
						uni.navigateTo({
							url: "/pages/order/orderSubmit"
						})
					}
				})
				// this.form.goods_type=this.product.goods_type;
				// this.form.goods_id=this.product.id
				// this.form.price=this.totalPrice
				// this.form.batch_id=this.product.batch_id
				// uni.showLoading({
				// 	mask:true,
				// 	title:"订单创建中"
				// })
				// createOrder(this.form).then(res=>{
				// 	uni.navigateTo({
				// 		url:`/pages/orderCenter/orderPay/orderPay?id=${res.data.order_id}&order_type=1`
				// 	})
				// })
			}
		}
	}
</script>

<style lang="scss">
.create-order{
	.btn{
		width: 686rpx;
		height: 88rpx;
		background-size:686rpx 88rpx;
		// background-image: url('@/static/img/bg/btn-big-bg.png');
		border-radius: 66rpx;
		text-align: center;
		line-height: 88rpx;
	}
}
</style>
